package cn.net.isir.controller.miniprogram;

import cn.net.isir.common.RequestObject;
import cn.net.isir.entity.Shop;
import cn.net.isir.service2.ShopService;
import cn.net.isir.utils.RequestUtils;
import cn.net.isir.common.ResultObject;
import cn.net.isir.service2.SlideShowService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liuxubo
 * @filename WxMinipSlideShowController.java
 * @package cn.net.isir.controller.manager
 * @email lxb@isir.net.cn
 * @date 2018/09/11
 * @comment
 * @since 1.7
 */

@RestController("minipSlideShowController")
@RequestMapping(value = "/minip/slideshow/")
public class SlideShowController {

    @Resource
    private SlideShowService slideShowService;
    @Resource
    private ShopService shopService;

    /**
     * 小程序获取轮播图列表
     *
     * @return list
     */
    @RequestMapping(method = RequestMethod.GET, value = "list")
    public ResultObject list(RequestObject obj, HttpServletResponse response) {
        //声明返回值
        ResultObject ro;
        //声明参数解码后的储存变量
        Map<String, Object> reqParamMap = new HashMap<>();
        //需要检查的字段名
        String[] columns = new String[]{"shopid"};
        //检查失败则返回缺失的字段提示
        if ((ro = RequestUtils.parametersCheck(obj, reqParamMap, columns)).getResult() != 200) {
            return ro;
        }
        String shopid = String.valueOf(reqParamMap.get("shopid"));
//        SlideShow slideShow = new SlideShow();
//        slideShow.setScope("shop_id_" + shopid);
//        List<SlideShow> list = slideShowService.selectList(slideShow);
//        if (list == null) {
//            list = new ArrayList<>();
//        }

        Shop shop = shopService.selectByPrimaryKey(shopid);
        ro.setResult(200);
        ro.setObject(shop.getIcon());
        return ro;
    }
}
